﻿using System.Linq;
using Diploma.Models.IRepositories;
using System;

namespace Diploma.Models.Repositories
{
    internal class GlobalTasksCompletionsRepository : IGlobalTasksCompletionsRepository
    {

        public GlobalTasksCompletionsRepository(DiplomaEntities dataContext)
        {
        }

        public GlobalTasksCompletion GetGlobalTaskCompletion(GlobalTask globalTask, Student student)
        {
            GlobalTasksCompletion completion =
                globalTask.GlobalTasksCompletions.Where(c => c.StudentId == student.UserId).FirstOrDefault();
            return completion;
          
        }

        public bool? GetCompletion(GlobalTask globalTask, Student student)
        {
            if (student.CollaborationRoom == null)
                return null;
            GlobalTasksCompletion completion =
                globalTask.GlobalTasksCompletions.Where(c => c.StudentId == student.UserId).FirstOrDefault();
            if (completion == null)
                return false;

            return completion.IsComplete;
        }
    }
}